package org.example.controller;

import org.example.entity.Air;
import org.example.service.IAirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/airs")
public class AirController {
    @Autowired
    private IAirService airService;

    @GetMapping
    public Page<Air> getAll(Air air, int page, int size){
        return airService.getAll(air, PageRequest.of(page - 1,size));
    }

    @GetMapping("/{id}")
    public Air get(@PathVariable Long id){
        return airService.get(id);
    }

    @PostMapping
    public Long add(@RequestBody Air air){
        return airService.add(air);
    }

    @PutMapping
    public Long update(@RequestBody Air air){
        return airService.update(air);
    }

    @DeleteMapping("/{id}")
    public int del(@PathVariable Long id){
        return airService.del(id);
    }

}
